package com.origin.niuke.slidingWindow;

/**
 * 最大值
 * 算法：滑动窗口
 *
 * @author yezh
 * @date 2022/12/29 21:58
 */
public class NC174 {

    public int maxValue (String s, int k) {
        // write code here
        int len = s.length();
        int ans = 0, t = 0, cur = 0, pow = (int) Math.pow(10, k - 1);
        while (t < len) {
            if (t >= k) cur -= (s.charAt(t - k) - '0') * pow;
            cur = cur * 10 + (s.charAt(t) - '0');
            ans = Math.max(ans, cur);
            ++t;
        }
        return ans;
    }

}
